bitkeeper revision 1.339.1.13 (3f133e41JY3T8AGVWEoFdVWiKkJdvQ)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 14 Jul 2003 23:35:29 +0000 (23:35 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 14 Jul 2003 23:35:29 +0000 (23:35 +0000)
xeno.c:
  Fix Xenolinux to mark protected disc partitions as read-only.

xenolinux-2.4.21-sparse/fs/partitions/xeno.c

index 0496d96044499450bd82051dd900ebc81fb9baaa..ef48583eb9ad3f8a45e003617fd672c22b669a2b 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/kernel.h>
 #include <asm/hypervisor.h>
 #include <linux/fs.h>
+#include <linux/blk.h>
 #include <linux/slab.h>
 #include <linux/genhd.h>
 #include <asm/hypervisor-ifs/block.h>
@@ -21,57 +22,57 @@ int xeno_partition(struct gendisk *hd,
                   int first_part_minor)
 {
     physdisk_probebuf_t *buf;
-    int i;
-    int minor;
-    int count;
+    int i, minor;
     
-    buf = kmalloc(sizeof(*buf), GFP_KERNEL);
-    if (!buf)
+    /* Privileged domains can read partition info themselves. */
+    if (start_info.flags & SIF_PRIVILEGED)
+        return 0;
+
+    /* This only deals with raw/direct devices (IDE & SCSI). */
+    switch ( xldev_to_physdev(bdev->bd_dev) & XENDEV_TYPE_MASK )
+    {
+    case XENDEV_IDE:
+    case XENDEV_SCSI:
+        break;
+    default:
+        return 0;
+    }
+
+    if ( (buf = kmalloc(sizeof(*buf), GFP_KERNEL)) == NULL )
         return -ENOMEM;
+
     buf->domain = start_info.dom_id;
     buf->start_ind = 0;
     buf->n_aces = PHYSDISK_MAX_ACES_PER_REQUEST;
 
     xenolinux_control_msg(XEN_BLOCK_PHYSDEV_PROBE, (char *)buf,
                          sizeof(*buf));
-    if (buf->n_aces == 0) {
-        kfree(buf);
-       return 0;
-    }
 
-    if (buf->n_aces == PHYSDISK_MAX_ACES_PER_REQUEST) {
-        kfree(buf);
-       return 0;
-    }
-
-    count = 0;
+    if ( buf->n_aces == PHYSDISK_MAX_ACES_PER_REQUEST )
+        printk(KERN_ALERT "Too many returns for xeno partition parser\n");
 
-    for (i = 0; i < buf->n_aces; i++) {
-        if (buf->entries[i].partition == 0) {
+    for ( i = 0; i < buf->n_aces; i++ )
+    {
+        if (buf->entries[i].partition == 0)
            continue;
-       }
-       /* Make sure the partition is actually supposed to be on this
-          disk. */
-       if (buf->entries[i].device != xldev_to_physdev(bdev->bd_dev)) {
+       if (buf->entries[i].device != xldev_to_physdev(bdev->bd_dev))
            continue;
-       }
-       /* This is a bit of a hack - the partition numbers are
-          specified by the hypervisor, and if we want them to match
-          up, this is what we need to do. */
-       count ++;
+        if (!(buf->entries[i].mode & PHYSDISK_MODE_W))
+        {
+            if (!(buf->entries[i].mode & PHYSDISK_MODE_R))
+                continue;
+            set_device_ro(bdev->bd_dev, 1);
+        }
        minor = buf->entries[i].partition + first_part_minor - 1;
        add_gd_partition(hd,
                         minor,
                         buf->entries[i].start_sect,
                         buf->entries[i].n_sectors);
     }  
-    kfree(buf);
 
-    /* If we didn't find any suitable Xeno partitions, try the other
-       types. */
-    if (!count)
-        return 0;
+    kfree(buf);
 
     printk("\n");
+
     return 1;
 }